@use 'sass:math';
@use 'sass:map';
@use '../core/theming/theming';
@use '../core/tokens/m2-utils';
@use '../core/tokens/m3-utils';

// Tokens that can't be configured through Angular Material's current theming API,
// but may be in a future version of the theming API.
@function get-unthemable-tokens() {
  @return ();
}

// Tokens that can be configured through Angular Material's color theming API.
@function get-color-tokens($theme) {
  $system: m2-utils.get-system($theme);

  @return (
    paginator-container-text-color: map.get($system, on-surface),
    paginator-container-background-color: map.get($system, surface),
    paginator-enabled-icon-color: map.get($system, on-surface-variant),
    paginator-disabled-icon-color: m3-utils.color-with-opacity(map.get($system, on-surface), 38%),
  );
}

// Tokens that can be configured through Angular Material's typography theming API.
@function get-typography-tokens($theme) {
  $system: m2-utils.get-system($theme);
  @return (
    paginator-container-text-font: map.get($system, body-small-font),
    paginator-container-text-line-height: map.get($system, body-small-line-height),
    paginator-container-text-size: map.get($system, body-small-size),
    paginator-container-text-tracking: map.get($system, body-small-tracking),
    paginator-container-text-weight: map.get($system, body-small-weight),
    paginator-select-trigger-text-size: map.get($system, body-small-size),
  );
}

// Tokens that can be configured through Angular Material's density theming API.
@function get-density-tokens($theme) {
  $system: m2-utils.get-system($theme);
  $density-scale: theming.clamp-density(map.get($system, density-scale), -5);
  $size-scale: (
    0: 56px,
    -1: 52px,
    -2: 48px,
    -3: 40px,
    -4: 40px,
    -5: 40px,
  );
  $form-field-size-scale: (
    0: 56px,
    -1: 52px,
    -2: 48px,
    -3: 44px,
    -4: 40px,
    -5: 36px,
  );
  $form-field-density-scale: if($density-scale > -4, -4, $density-scale);
  $form-field-height: map.get($form-field-size-scale, $form-field-density-scale);

  // We computed the desired height of the form-field using the density configuration. The
  // spec only describes vertical spacing/alignment in non-dense mode. This means that we
  // cannot update the spacing to explicit numbers based on the density scale. Instead, we
  // determine the height reduction and equally subtract it from the default `top` and `bottom`
  // padding that is provided by the Material Design specification.
  $form-field-vertical-deduction: math.div(56px - $form-field-height, 2);
  $form-field-vertical-padding: 16px - $form-field-vertical-deduction;

  @return (
    paginator-container-size: map.get($size-scale, $density-scale),
    paginator-form-field-container-height: $form-field-height,
    paginator-form-field-container-vertical-padding: $form-field-vertical-padding,
    paginator-touch-target-display: if($density-scale < -2, none, block),
  );
}
